//----------------------------------------------------------------------------
// View 'Medewerkers'
//----------------------------------------------------------------------------
Ti.include('lib/include.js');
Ti.include('lib/constants.js');


var winMdw = Titanium.UI.currentWindow;
winMdw.addEventListener('focus', function(e) {
   log("Window 'Medewerkers' actief");
   coverFlowMdw.selected = 0;
   getNameForImage(coverFlowMdw.selected);
});

var namenLijst = ['M. Franssen\nHuisarts', 
   'M.C.P Uitterhoeve-Prins\nHuisarts', 
   'C.N.P. Bruijns\nHuisarts', 
   'P.H.A. le Doux\nHuisarts', 
   'Claudia Cremer\nAssistente', 
   'Debby Smeets-Nijpels\nAssistente', 
   'Mandy Klaassens-Leonard\nAssistente', 
   'Susanne Söffgen-Schulz\nAssistente'];

var mdwImages = ['images/mdw/huisartsen/Margot_medium.png', 
   'images/mdw/huisartsen/Marjolijn_medium.png', 
   'images/mdw/huisartsen/Coen_medium.png', 
   'images/mdw/huisartsen/Philippe_medium.png', 
   'images/mdw/assistentes/Claudia_medium.png', 
   'images/mdw/assistentes/Debby_medium.png', 
   'images/mdw/assistentes/Mandy_medium.png', 
   'images/mdw/assistentes/Susan_medium.png'];

var images = [];
if (isIpad()) {
   for(var i=0,j=mdwImages.length; i<j; i++){
     images.push({
      image: mdwImages[i],
      height: "90%",
      width: "90%"
     });
   };
}
else if (isIphone()) {
   for(var i=0,j=mdwImages.length; i<j; i++){
     images.push({
      image: mdwImages[i],
      height: "50%",
      width: "50%"
     });
   };   
}

//----- Coverflow view
var coverFlowMdw = Ti.UI.iOS.createCoverFlowView({
   images : images,
   selected : 0
});
coverFlowMdw.addEventListener('change', function(e) {
   getNameForImage(coverFlowMdw.selected);
});

//----- Buttons
var btnLeft = Titanium.UI.createButton({
   image : '/images/icons/icon_arrow_left.png'
});
btnLeft.addEventListener('click', function(e) {
   var i = coverFlowMdw.selected - 1;
   if (i < 0) {
      i = 0;
   }
   coverFlowMdw.selected = i;
   getNameForImage(coverFlowMdw.selected);
});

var btnRight = Titanium.UI.createButton({
   image : '/images/icons/icon_arrow_right.png'
});
btnRight.addEventListener('click', function(e) {
   var i = coverFlowMdw.selected + 1;
   if (i >= images.length) {
      i = images.length - 1;
   }
   coverFlowMdw.selected = i;
   getNameForImage(coverFlowMdw.selected);
});



//----- Add UI elements
winMdw.add(coverFlowMdw);

if (isIpad()) {
   //Create extra toolbar on iPad
   var flexSpace = Titanium.UI.createButton({
      systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
   });
   var navToolBar = Titanium.UI.iOS.createToolbar({
       items:[flexSpace, btnLeft, flexSpace, btnRight, flexSpace],
       bottom:0,
       borderTop:false,
       borderBottom:false
   }); 
   if (isIOS7Plus()) {
      navToolBar.setOpacity(1.0);
   }
   else {
      navToolBar.setBarColor(donkergroen);
      navToolBar.setColor(wit);
   }

   winMdw.add(navToolBar);
} 
else if (isIphone()) {
   winMdw.leftNavButton = btnLeft;
   winMdw.rightNavButton = btnRight;
}



//----- Functions
function getNameForImage(imagenr) {
   log("Naam ophalen bij afbeelding met ID " +imagenr);
   messageLabel.text = namenLijst[imagenr];
   messageView.add(messageLabel);
   winMdw.add(messageView);
}
